import "dotenv/config";
import type { FastifyServerOptions } from "fastify";
import Fastify from "fastify";
import appService from "./app.js";
import { getLoggerConfig, initLogger } from "./utils/logger.js";

const options: FastifyServerOptions = {
	logger: getLoggerConfig("admin-fastify", Boolean(process.env.DEBUG)),
	trustProxy: true,
};

const app = Fastify(options);

app.register(appService);

initLogger(app.log);

const start = async () => {
	try {
		await app.listen({ port: Number(process.env.PORT || 3000) });
	} catch (err) {
		app.log.error(err);
		process.exit(1);
	}
};

// Start listening.
start().then();
